package com.pie4cloud.pie.job.executor.mapper;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.PreparedStatementCallback;

public class CommonPreparedStatementCallBack implements PreparedStatementCallback<Boolean> {

	private Map<String, String> data;
	
	private String[] cols;
	public CommonPreparedStatementCallBack(Map<String, String> data,String[] cols) {
		
		this.data = data;
		this.cols = cols;
	}
	@Override
	public Boolean doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
		
		for (int i = 1; i <= cols.length; i++) {
			ps.setString(i, data.get(cols[i - 1]));
		}
		ps.execute();
		return true;
	}

}
